<?php

$installer = $this;
$installer->startSetup();


$installer->run("
                CREATE TABLE IF NOT EXISTS`{$installer->getTable('zhishidi_express/shipping_type')}` (
                    `type_id` TINYINT(4) unsigned NOT NULL AUTO_INCREMENT,
                    `type_code` VARCHAR(32) NOT NULL,
                    `type_name` VARCHAR(64) NOT NULL,
                    `type_discount` DOUBLE DEFAULT 0,
                    `type_surcharge` DOUBLE DEFAULT 0,
                    `type_weight_unit` FLOAT NOT NULL,
                    `type_max_weight` FLOAT DEFAULT 0,
                    `type_handle` ENUM('table_rate','fixed', 'fixed_table_rate') NOT NULL,
                    `type_sep_weight` FLOAT DEFAULT 0,
                    `type_sep_weight_unit` FLOAT DEFAULT 0,
                    `type_sep_group` TINYINT(4) DEFAULT 0,
                    `type_status`  ENUM('public','hidden') DEFAULT 'public',
                    `type_note` VARCHAR(255) NULL,                    
                     PRIMARY KEY (`type_id`)
                )ENGINE=InnoDB DEFAULT CHARSET = UTF8;

                 CREATE TABLE IF NOT EXISTS`{$installer->getTable('zhishidi_express/shipping_zone_group')}` (
                    `group_id` TINYINT(4) unsigned NOT NULL AUTO_INCREMENT,
                    `group_name` VARCHAR(64) NOT NULL,
                    `group_status`  ENUM('public','hidden') DEFAULT 'public',
                    PRIMARY KEY (`group_id`)
                 )ENGINE=InnoDB DEFAULT CHARSET = UTF8;


                CREATE TABLE IF NOT EXISTS`{$installer->getTable('zhishidi_express/shipping_zone')}` (
                    `zone_id` SMALLINT(6) unsigned NOT NULL AUTO_INCREMENT,
                    `zone_group` TINYINT(4) DEFAULT 0,
                    `zone_type` TINYINT(4) unsigned NOT NULL,
                    `zone_name` VARCHAR(64) NOT NULL,
                    `zone_status`  ENUM('public','hidden') DEFAULT 'public',
                    PRIMARY KEY (`zone_id`),
                    CONSTRAINT FOREIGN KEY (`zone_type`) REFERENCES {$installer->getTable('zhishidi_express/shipping_type')} (`type_id`) ON DELETE CASCADE ON UPDATE CASCADE
                )ENGINE=InnoDB DEFAULT CHARSET = UTF8;

                CREATE TABLE IF NOT EXISTS `{$installer->getTable('zhishidi_express/shipping_zone_config')}` (
                    `zone_id` SMALLINT(6) unsigned NOT NULL,
                    `zone_price` DOUBLE NOT NULL,
                    `zone_unit` DOUBLE NOT NULL,
                     CONSTRAINT FOREIGN KEY (`zone_id`) REFERENCES {$installer->getTable('zhishidi_express/shipping_zone')} (`zone_id`) ON DELETE CASCADE ON UPDATE CASCADE
                )ENGINE=InnoDB DEFAULT CHARSET = UTF8;

                CREATE TABLE IF NOT EXISTS `{$installer->getTable('zhishidi_express/shipping_zone_map')}` (
                    `map_id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
                    `map_zone` SMALLINT(6) unsigned NOT NULL,
                    `map_country` VARCHAR(10) NOT NULL,
                    `map_state` VARCHAR(64)  NULL,
                `map_status`  ENUM('public','hidden') DEFAULT 'public',                
                     PRIMARY KEY (`map_id`),
                     CONSTRAINT FOREIGN KEY (`map_zone`) REFERENCES {$installer->getTable('zhishidi_express/shipping_zone')} (`zone_id`) ON DELETE CASCADE ON UPDATE CASCADE
                )ENGINE=InnoDB DEFAULT CHARSET = UTF8;

                CREATE TABLE IF NOT EXISTS `{$installer->getTable('zhishidi_express/shipping_zone_table_rate')}` (
                    `rate_id`   INT(11) unsigned NOT NULL AUTO_INCREMENT,
                    `rate_zone` SMALLINT(6) unsigned NOT NULL,
                    `rate_from` FLOAT NOT NULL,
                    `rate_to` FLOAT NOT NULL,
                    `rate_price` DOUBLE NOT NULL,
                     PRIMARY KEY (`rate_id`),
                     CONSTRAINT FOREIGN KEY (`rate_zone`) REFERENCES {$installer->getTable('zhishidi_express/shipping_zone')} (`zone_id`) ON DELETE CASCADE ON UPDATE CASCADE
                )ENGINE=InnoDB DEFAULT CHARSET = UTF8;
                "
);

                     

$installer->endSetup();
?>
